// 高阶组件  参数为组件 返回值为新组件的函数
// 作用 给组件添加额外的功能  让组件可以复用逻辑

import React, { Component } from 'react'





export const withCount = (Com) => {
    class Count extends Component {
        
        state = {
            count:0
        }
        
        componentDidMount() {
            this.timer = setInterval(() => {
                this.setState({
                    count:this.state.count + 1
                })
            },1000)
        }
        
        componentWillUnmount() {
            clearInterval(this.timer)
    
        }


        render() {
            console.log(this.props)
            return (
                <Com count={this.state.count}{...this.props}/>
            )
        }
    }
    return Count
}